﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace homework9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btn_select_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = false;
            fileDialog.Title = "请选择一个url";
            fileDialog.Filter = "url(*html)|*.html";
            if(fileDialog.ShowDialog() == DialogResult.OK)
            {
                txt_url.Text = fileDialog.FileName;
            }
        }

        //下载
        private string Download()
        {
            WebClient webClient = new WebClient();
            webClient.Encoding = Encoding.UTF8;
            string html = webClient.DownloadString(txt_url.Text);
            return html;
        }

        //匹配
        private void btn_match_Click(object sender, EventArgs e)
        {
            //正则表达式
            string pattern_Num = @"[0-9]{11}";
            string pattern_Email = @"[0-9]+@[a-z]+.[a-z]+";
            //包装为类
            Regex regex_Num = new Regex(pattern_Num);
            Regex regex_Email = new Regex(pattern_Email);

            Match match_Num = regex_Num.Match(Download());
            Match match_Email = regex_Email.Match(Download());

            txt_email.Text = match_Email.Value;
            txt_phoneNum.Text = match_Num.Value;
        }
    }
}
